package LN.Varios;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
//persistir = f
public class Conexion {

    private Connection conn;
    private Statement stmt;
    private ResultSet rs;

    public Conexion() {
        this.conn = null;
        this.stmt = null;
        this.rs = null;
    }

    public Connection AbrirConex() {
        try {
            String login = "postgres";
            String password = "verydis1750";
            String url = "jdbc:postgresql://localhost:5432/Verydis";
            Class.forName("org.postgresql.Driver").newInstance();
            conn = DriverManager.getConnection(url, login, password);
            stmt = conn.createStatement();
            return conn;
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException ex) {
            System.out.println("Error en la Conexion a la Base de Datos");
            System.out.println(ex.toString());
            return conn;

        }
    }

    public void CerrarConex() {
        try {
            conn.close();
            System.out.println("Conexion Cerrada");
        } catch (Exception ex) {
            System.out.println("Error al desconectar Base de datos");
        }
    }
}
